package com.itheima.easy.task;
// Import necessary packages
import com.itheima.easy.service.ReservationService;
import com.itheima.easy.vo.ReservationVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.util.List;

@Component
public class ReservationJob {

    @Autowired
    private ReservationService reservationService;


    @Scheduled(cron = "0 0 * * * *")
    public void updateVisitReservationStatusToExpiredIfNotCompleted() {

        List<ReservationVo> reservations = reservationService.findAll(null, LocalDateTime.now().minusDays(1));

        for (ReservationVo reservation : reservations) {
            // 则将预约状态更新为过期
            reservationService.updateVisitReservationStatusToExpiredIfNotCompleted(reservation.getId());
        }
    }
}
